package org.example.gochannel;

public abstract class ChannelExecWrapper<T> {
    JavaGoChannel<T> channel = null;


    public ChannelExecWrapper(JavaGoChannel<T> channel) {
        this.channel = channel;
    }

    protected abstract void exec(T para);

    private T takeElem(long oft) throws InterruptedException {
        if (oft > 0)
            return channel.out(oft);
        else
            return channel.out(20);
    }

    public boolean watchAndExecOnce(long oft) throws InterruptedException {
        T t = takeElem(oft);
        if (t == null) return false;

        exec(t);
        return true;
    }
}
